home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_09 / single / mobject.h < prev   
Encoding:
C/C++ Source or Header  |  1994-06-29  |  1.6 KB  |  70 lines

  1. //  Listing 3
  2. //    mobject.h
  3. //
  4. //  Copyright Singleton Systems Ltd 1994
  5.  
  6. #if !defined (_MOBJECT_H_)
  7. #define _MOBJECT_H_
  8.  
  9. #if !defined (_FARHEAPB_H_)
  10. #include    "farheapb.h"
  11. #endif 
  12.  
  13. #define FP_MOBJECT MemoryObject FAR *
  14. #define VP_MOBJECT MemoryObject BASED_VOID *
  15. #define MO_BASED_VOID_FROM_LP(lp) \
  16.                 ((VP_MOBJECT) (OFFSETOF(lp)))
  17.  
  18. #if defined (_DEBUG)
  19. #define MO_DEBUG_NEW new(THIS_FILE, __LINE__)
  20. #else
  21. #define MO_DEBUG_NEW new
  22. #endif 
  23.  
  24. class FAR MemoryObject
  25. {
  26. friend FarHeapBlock::FarHeapBlock ();  
  27. private: 
  28. HGLOBAL    my_heap_block;
  29. MemoryObject BASED_VOID * prev_mo, 
  30.              BASED_VOID * next_mo; 
  31. unsigned int mo_block_size;
  32. enum flag_values {unallocated = 0, allocated = 1};
  33.  
  34. // ... debugging code not shown here 
  35. //     due to space constraints ...
  36.  
  37. //  Functions
  38. public:
  39. static void FAR * AllocateBlock (int required_size);
  40. static void ReturnBlock (void FAR * p_block);
  41.  
  42. void FAR * operator new (size_t size); 
  43. //  standard operator new, used for derived classes.
  44. private:
  45. void FAR * operator new (size_t, size_t size);
  46. //  Extended operator new, used by AllocateBlock 
  47. //  and standard operator new
  48.  
  49. public:
  50.  
  51. // ... debugging code not shown here 
  52. //     due to space constraints ...
  53.  
  54.  
  55. void operator delete (void FAR * p_mo);
  56. MemoryObject ();
  57. ~MemoryObject ();
  58.  
  59. private:
  60. static FP_MOBJECT FindFreeSpace 
  61.             (size_t size, FP_FHB & block_allocated);
  62. void SetAllocationFlag (int flag_val);
  63. void SetFirstMemoryObject (HGLOBAL hglob, 
  64.                            unsigned size);
  65.  
  66. // ... code not shown here 
  67. //     due to space constraints ...
  68.  
  69. };
  70.